package room_event

import (
	"github.com/spf13/cast"
	"longmen/server/config/global"
	"longmen/server/internal/rpc/tencentim/cache"
	chat2 "longmen/server/internal/rpc/tencentim/chat"
	cache2 "longmen/server/pkg/db/redis/cache"
	pb "longmen/server/pkg/protobuf"
)

// 登出处理
func handlingLogout(usr *chat2.ClientUser) (ret *pb.CallbackResp, err error) {
	defer func() {
		//crontab.ReplayChatClientHub.LeaveRoom()
	}()
	anchor, _ := cache2.GetUserFullInfo(usr.RoomId)
	if anchor.Id > 0 {
		cache.SetEntryExitTimes(usr, "out")
	}
	//cache.RoomUserOffline(usr.RoomId, usr.UserId) // 更新 cache - 离开 房间
	return &pb.CallbackResp{}, nil
}

// 退出回调处理
func CallBackHandlingLogout(req *pb.CallbackReq) (ret *pb.CallbackResp, err error) {
	if req.GetInfo().GetAction() != "Login" {
		global.Log.Debugf("CallBackHandlingLogout req:%+v", req)
		user := chat2.GetClientUser(cast.ToInt(req.GetInfo().GetTo_Account()))
		if user != nil {
			handlingLogout(user)
		}
	}
	return &pb.CallbackResp{}, nil
}
